import java.util.*;

public class Test {
    public static void main(String[] args) {
        PriorityQueue<int[]> queue = new PriorityQueue<>();
        for (int[] x : queue) {

        }
    }
}
class Solution {
    public List<Integer> filterRestaurants(int[][] restaurants, int veganFriendly, int maxPrice, int maxDistance) {
        List<Integer> ans = new ArrayList<>();
        PriorityQueue<int[]> queue = new PriorityQueue<>(new Comparator<int[]>() {
            public int compare(int[] o1, int[] o2) {
                if(o1[1] == o2[1])
                    return o2[0]-o1[0];
                return o2[1]-o1[1];
            }
        });
        for(int[] x : restaurants){
            if(x[2]>=veganFriendly && x[3]<=maxPrice && x[4]<=maxDistance)
                queue.offer(x);
        }
        while(!queue.isEmpty()){
            ans.add(queue.poll()[0]);
        }
        return ans;
    }
}
class Solution1 {
    public List<Integer> findSubstring(String s, String[] words) {
        List<Integer> ans = new ArrayList<>();
        int len = words[0].length();
        int cnt = words.length;
        Map<String,Integer> hash = new HashMap<>();
        for(String x : words)
            hash.put(x,hash.getOrDefault(x,0)+1);
        for(int i=0; i<len; i++){
            Map<String,Integer> map = new HashMap<>();
            for(int l=i,r=i,count=0; r+len<=s.length(); r+=len){
                String tmp = s.substring(r,r+len);
                map.put(tmp,map.getOrDefault(tmp,0)+1);
                if(map.get(tmp)<=hash.getOrDefault(tmp,0)) count++;
                if(r-l+len > cnt*len){
                    String out = s.substring(l,l+len);
                    if(map.get(out) <= hash.getOrDefault(out,0))
                        count--;
                    map.put(out,map.get(out)-1);
                    l += len;
                }
                if(count == cnt) ans.add(l);
            }
        }
        return ans;
    }
}
class Solution2 {
    public String minWindow(String s, String t) {
        Map<Character,Integer> map = new HashMap<>();
        int len = t.length();
        for(char ch : t.toCharArray()){
            map.put(ch,map.getOrDefault(ch,0)+1);
        }
        int[] ans = new int[3];
        Arrays.fill(ans,Integer.MAX_VALUE);
        Map<Character,Integer> hash = new HashMap<>();
        for(int l=0,r=0,cnt=0; r<s.length(); r++){
            char ch = s.charAt(r);
            hash.put(ch,hash.getOrDefault(ch,0)+1);
            if(hash.get(ch)<=map.getOrDefault(ch,0)) cnt++;
            while(cnt == len){
                if(ans[0]>r-l+1){
                    ans[0] = r-l+1;
                    ans[1] = l;
                    ans[2] = r;
                }
                char out = s.charAt(l++);
                if(hash.get(out)<=map.getOrDefault(out,0)) cnt--;
                hash.put(out,hash.get(out)-1);
            }
        }
        for(int i=0; i<3; i++){
            if(ans[i]==Integer.MAX_VALUE){
                return "";
            }
        }
        return s.substring(ans[1],ans[2]+1);
    }
}
